﻿require.config({
  urlArgs: "version=20170501",
  paths: {
    'jquery': '../packages/jquery-2.14-min',
    'bootstrap': '../../bootstrap/js/bootstrap.min',
  },
  shim: {
    'bootstrap': {
      deps: ['jquery'],
      exports: 'bootstrap'
    }
  }
});




require(['jquery','bootstrap'], function ($) {

	var myChart = echarts.init(document.getElementById('content-right-classify1'));
  $('#graph-2001').click(function () {
  	drawGraph_2001();
	  $('#graph-show').modal('show');
  });
  $('#graph-2002').click(function () {
  	drawGraph_2002();
	  $('#graph-show').modal('show');
  });
  function drawGraph_2001() {
		/**
		 *ajax获取相应的数据 国家/地区专利申请量排名(前10位)
		 */
		dataX = [];
	  	valueY1 = [];
	  	valueY2 = [];
	  	valueY3 = [];
		$.ajax({
		type : 'GET',
		url : '/draw/graph/2001',
		//data : jsonda,
		cache: false,
		async:false,
		//contentType: "application/json; charset=utf-8",
		dataType : 'json',
		success : function(res) {
		    valueY1 = res.graph_2001_y_value;
			valueY2 = 0;
			valueY3 = 0;
			dataX = res.xAxis;
		},
		error : function(xml, err, throwInfo) {
			alert(err);
		}
		});
		myChart.clear();
	
		

option = {
      title: {
      text: '国家/地区专利申请量排名(前10位)',
      x: 'center',
      y: 0
  },
  tooltip : {
      trigger: 'axis',
      axisPointer : {            // 坐标轴指示器，坐标轴触发有效
          type : 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
      }
  },
  toolbox: {
      show : true,
      y: 'bottom',
      feature : {
          saveAsImage : {show: true}
      }
  },
  grid: {
      left: '3%',
      right: '4%',
      bottom: '3%',
      containLabel: true
  },
  xAxis:  {
	  type: 'category',
      data: dataX, 
      axisLabel: {
      	 textStyle: {fontSize: 12},
interval: 0,  
 formatter: function (name) {
  return (name.length > 8 ? (name.slice(0,8)+"...") : name ); 
}
}

  },
  yAxis: {
      name:'专利申请量(件)',
     	nameLocation:'middle',
    	nameGap: 25,
      type: 'value'
},
  series: [
      
      {
          name: '专利申请量(件)',
          type: 'bar',
          stack: '总量',
          label: {
              normal: {
                  show: true,
                  position: 'insideRight'
              }
          },
          data: valueY1
      }
  ]
};
	myChart.setOption(option);
	//window.onresize = myChart.resize;
		 
	}
	
	
function drawGraph_2002() {
	myChart.clear();
	var xAxisData = [];
	var data1 = [];
	var data2 = [];
	for (var i = 0; i < 100; i++) {
	    xAxisData.push('类目' + i);
	    data1.push((Math.sin(i / 5) * (i / 5 -10) + i / 6) * 5);
	    data2.push((Math.cos(i / 5) * (i / 5 -10) + i / 6) * 5);
	}
		option = {
			    title: {
			        text: '柱状图动画延迟'
			    },
			    legend: {
			        data: ['bar', 'bar2'],
			        align: 'left'
			    },
			    toolbox: {
			        // y: 'bottom',
			        feature: {
			            magicType: {
			                type: ['stack', 'tiled']
			            },
			            dataView: {},
			            saveAsImage: {
			                pixelRatio: 2
			            }
			        }
			    },
			    tooltip: {},
			    xAxis: {
			        data: xAxisData,
			        silent: false,
			        splitLine: {
			            show: false
			        }
			    },
			    yAxis: {
			    },
			    series: [{
			        name: 'bar',
			        type: 'bar',
			        data: data1,
			        animationDelay: function (idx) {
			            return idx * 10;
			        }
			    }, {
			        name: 'bar2',
			        type: 'bar',
			        data: data2,
			        animationDelay: function (idx) {
			            return idx * 10 + 100;
			        }
			    }],
			    animationEasing: 'elasticOut',
			    animationDelayUpdate: function (idx) {
			        return idx * 5;
			    }
			};
		 myChart.setOption(option);
	}
});